class Solution {
public:
    int findMin(vector<int>& nums) {
        int l = 0, r = nums.size() - 1;
        while (l < r) {
            int mid = (r - l) / 2 + l;
            if (nums[mid] < nums[r]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return nums[l];
    }
};

class Solution {
public:
    int findMin(vector<int>& nums) {
        int left = 0;
        int right = nums.size();
        while(left < right)
        {
            if(nums[0] <= nums[nums.size()-1])
                return nums[0];
            if(left>0 && nums[left]<nums[left-1])
                return nums[left];

            int mid = (left+right) / 2;
            if(nums[mid] < nums[mid-1])
                return nums[mid];
            else if(nums[mid] > nums[left])
                left = mid + 1;
            else
                right = mid;
        }

        return nums[0];
    }
};